﻿using System;
using Pixysoft.Framework.XSchEmA.Entity;
using System.Collections.Generic;

namespace Pixysoft.Framework.XSchEmA
{
    /// <summary>
    /// 对内存对象修改
    /// </summary>
    public interface IDbModifier : IColumnModifier, ITableModifier
    {
    }

    public interface ITableModifier
    {
        /// <summary>
        /// 不支持跳过 异常抛出
        /// </summary>
        /// <param name="database"></param>
        /// <param name="tableName"></param>
        /// <returns></returns>
        TableSchema CreateTable(DatabaseSchema database, string tableName);

        /// <summary>
        /// 不支持跳过 异常抛出
        /// </summary>
        /// <param name="databaseTo"></param>
        /// <param name="databaseFrom"></param>
        /// <param name="tableFrom"></param>
        void CreateTable(DatabaseSchema databaseTo, DatabaseSchema databaseFrom, TableSchema tableFrom);

        /// <summary>
        /// 不支持跳过 异常抛出
        /// </summary>
        /// <param name="database"></param>
        /// <param name="tableName"></param>
        void DeleteTable(DatabaseSchema database, string tableName);
    }

    public interface IColumnModifier
    {
        /// <summary>
        /// 不支持false 异常抛出
        /// </summary>
        /// <param name="database"></param>
        /// <param name="fk"></param>
        /// <returns></returns>
        bool CreateForeignKey(DatabaseSchema database, ForeignKeySchema fk);

        /// <summary>
        /// 不支持false 异常抛出
        /// </summary>
        /// <param name="database"></param>
        /// <param name="fk"></param>
        /// <returns></returns>
        bool DeleteForeignKey(DatabaseSchema database, ForeignKeySchema fk);

        /// <summary>
        /// 不支持抛出 异常抛出
        /// </summary>
        /// <param name="database"></param>
        /// <param name="tableName"></param>
        /// <returns></returns>
        ForeignKeySchema[] DeleteForeignKeys(DatabaseSchema database, string tableName);



        /// <summary>
        /// 不支持抛出 异常抛出
        /// </summary>
        /// <param name="database"></param>
        /// <param name="pkName"></param>
        /// <param name="table"></param>
        /// <param name="columns"></param>
        /// <returns></returns>
        PrimaryKeySchema CreatePrimaryKey(DatabaseSchema database,
            string pkName, TableSchema table, List<ColumnSchema> columns);

        /// <summary>
        /// 不支持false 异常抛出
        /// </summary>
        /// <param name="database"></param>
        /// <param name="pk"></param>
        /// <returns></returns>
        bool CreatePrimaryKey(DatabaseSchema database, PrimaryKeySchema pk);

        /// <summary>
        /// 不支持false 异常抛出
        /// </summary>
        /// <param name="database"></param>
        /// <param name="pk"></param>
        /// <returns></returns>
        bool DeletePrimaryKey(DatabaseSchema database, PrimaryKeySchema pk);



        /// <summary>
        /// 不支持抛出 异常抛出
        /// </summary>
        /// <param name="database"></param>
        /// <param name="constraintName"></param>
        /// <param name="table"></param>
        /// <param name="columns"></param>
        /// <returns></returns>
        UniqueSchema CreateUnique(DatabaseSchema database,
            string constraintName, TableSchema table, List<ColumnSchema> columns);

        /// <summary>
        /// 不支持false 异常抛出
        /// </summary>
        /// <param name="database"></param>
        /// <param name="unique"></param>
        /// <returns></returns>
        bool CreateUnique(DatabaseSchema database, UniqueSchema unique);

        /// <summary>
        /// 不支持false 异常抛出
        /// </summary>
        /// <param name="database"></param>
        /// <param name="unique"></param>
        /// <returns></returns>
        bool DeleteUnique(DatabaseSchema database, UniqueSchema unique);


        /// <summary>
        /// 不支持抛出 异常抛出
        /// </summary>
        /// <param name="database"></param>
        /// <param name="constraintName"></param>
        /// <param name="table"></param>
        /// <param name="columns"></param>
        /// <returns></returns>
        IndexSchema CreateIndex(DatabaseSchema database, string constraintName, TableSchema table, List<ColumnSchema> columns);

        /// <summary>
        /// 不支持false 异常抛出
        /// </summary>
        /// <param name="database"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        bool CreateIndex(DatabaseSchema database, IndexSchema index);

        /// <summary>
        /// 不支持false 异常抛出
        /// </summary>
        /// <param name="database"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        bool DeleteIndex(DatabaseSchema database, IndexSchema index);


        /// <summary>
        /// 不支持抛出 异常抛出
        /// </summary>
        /// <param name="database"></param>
        /// <param name="table"></param>
        /// <param name="columnName"></param>
        /// <returns></returns>
        ColumnSchema AddColumn(DatabaseSchema database, TableSchema table, string columnName);

        /// <summary>
        /// 不支持false 异常抛出
        /// </summary>
        /// <param name="database"></param>
        /// <param name="table"></param>
        /// <param name="column"></param>
        /// <returns></returns>
        bool AddColumn(DatabaseSchema database, TableSchema table, ColumnSchema column);

        /// <summary>
        /// 不支持false 异常抛出
        /// </summary>
        /// <param name="database"></param>
        /// <param name="column"></param>
        /// <returns></returns>
        bool DeleteColumn(DatabaseSchema database, ColumnSchema column);



        /// <summary>
        /// 修改被引用的外键
        /// Pre Condition:表名经过验证
        /// </summary>
        /// <param name="input">The input.</param>
        /// <param name="datatype">The datatype.</param>
        /// <param name="database">The database.</param>
        /// <param name="table">The table.</param>
        /// <param name="column">The column.</param>
        /// <returns></returns>
        bool ChangeColumnName(DatabaseSchema database, TableSchema table, ColumnSchema column, string columnName);

        /// <summary>
        /// Changes the memo.
        /// </summary>
        /// <param name="comment">The comment.</param>
        /// <param name="column">The column.</param>
        /// <returns></returns>
        bool ChangeComment(ColumnSchema column, string comment);

        /// <summary>
        /// Changes the default value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="datatype">The datatype.</param>
        /// <param name="column">The column.</param>
        /// <returns></returns>
        bool ChangeDefaultValue(ColumnSchema column, string value);

        /// <summary>
        /// 修改类型
        /// </summary>
        /// <param name="input">The input.</param>
        /// <param name="datatype">The datatype.</param>
        /// <param name="database">The database.</param>
        /// <param name="table">The table.</param>
        /// <param name="column">The column.</param>
        /// <returns></returns>
        bool ChangeDataType(DatabaseSchema database, TableSchema table, ColumnSchema column, DataTypeSchema dataType);

    }
}
